package zaphod.toy.sampleserver;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;


public class SampleServer
{
    private static final int PORT = 1025;


    public static void main( String args[] )
    {
        ServerSocket ss;
        Socket connection;
        Thread it, ot;
        try
        {
            ss = new ServerSocket( PORT );
            System.out.println( "Listening for connections on ports : "
                    + ss.getLocalPort() );
            while ( true )
            {
                connection = ss.accept();
                System.out.println( "Connection established with" + connection );
                it =
                        new Thread( new InputThread(
                                connection.getInputStream() ) );
                it.start();
                ot =
                        new Thread( new OutputThread(
                                connection.getOutputStream(),it ) );
                ot.start();
                try
                {
                    ot.join();
                    it.join();
                }
                catch ( InterruptedException e )
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        catch ( IOException e )
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}